class Solution
{
public:
    int minNonZeroProduct(int p)
    {
        auto fastPower = [](long long base, long long exp, long long mod)
        {
            long long result = 1;
            while (exp > 0)
            {
                if (exp & 1)
                {
                    result *= base;
                    result %= mod;
                }
                exp = exp >> 1;
                base *= base;
                base %= mod;
            }
            return result;
        };

        long long mod = 1'0000'0000'7ll;
        long long count = fastPower(2, p, mod) - 1;
        long long base = count - 1;
        long long exp = (1ll << (p - 1)) - 1;
        long long result = count * fastPower(base, exp, mod) % mod;
        return result;
    }
};